home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsnotify.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.6 KB  |  94 lines

  1. /* Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsnotify.h,v 1.2 2000/09/19 19:00:30 lpd Exp $ */
  20. /* Notification machinery */
  21.  
  22. #ifndef gsnotify_INCLUDED
  23. #  define gsnotify_INCLUDED
  24.  
  25. #include "gsstype.h"        /* for extern_st */
  26.  
  27. /*
  28.  * An arbitrary number of clients may register themselves to be notified
  29.  * when an event occurs.  Duplicate registrations are not detected.  Clients
  30.  * must unregister themselves when they are being freed (finalized), if not
  31.  * before.  Objects that provide notification must notify clients when the
  32.  * object is being freed (finalized): in this event, and only in this event,
  33.  * event_data = NULL.
  34.  */
  35.  
  36. /* Define the structure used to keep track of registrations. */
  37. #define GS_NOTIFY_PROC(proc)\
  38.     int proc(P2(void *proc_data, void *event_data))
  39. typedef GS_NOTIFY_PROC((*gs_notify_proc_t));
  40. typedef struct gs_notify_registration_s gs_notify_registration_t;
  41. struct gs_notify_registration_s {
  42.     gs_notify_proc_t proc;
  43.     void *proc_data;
  44.     gs_notify_registration_t *next;
  45. };
  46. #define private_st_gs_notify_registration() /* in gsnotify.c */\
  47.   gs_private_st_ptrs2(st_gs_notify_registration, gs_notify_registration_t,\
  48.     "gs_notify_registration_t", notify_registration_enum_ptrs,\
  49.     notify_registration_reloc_ptrs, proc_data, next)
  50.  
  51. /* Define a notification list. */
  52. typedef struct gs_notify_list_s {
  53.     gs_memory_t *memory;    /* for allocating registrations */
  54.     gs_notify_registration_t *first;
  55. } gs_notify_list_t;
  56. /* The descriptor is public for GC of embedded instances. */
  57. extern_st(st_gs_notify_list);
  58. #define public_st_gs_notify_list() /* in gsnotify.c */\
  59.   gs_public_st_ptrs1(st_gs_notify_list, gs_notify_list_t,\
  60.     "gs_notify_list_t", notify_list_enum_ptrs, notify_list_reloc_ptrs,\
  61.     first)
  62. #define st_gs_notify_list_max_ptrs 1
  63.  
  64. /* Initialize a notification list. */
  65. void gs_notify_init(P2(gs_notify_list_t *nlist, gs_memory_t *mem));
  66.  
  67. /* Register a client. */
  68. int gs_notify_register(P3(gs_notify_list_t *nlist, gs_notify_proc_t proc,
  69.               void *proc_data));
  70.  
  71. /*
  72.  * Unregister a client.  Return 1 if the client was registered, 0 if not.
  73.  * If proc_data is 0, unregister all registrations of that proc; otherwise,
  74.  * unregister only the registration of that procedure with that proc_data.
  75.  */
  76. int gs_notify_unregister(P3(gs_notify_list_t *nlist, gs_notify_proc_t proc,
  77.                 void *proc_data));
  78.  
  79. /* Unregister a client, calling a procedure for each unregistration. */
  80. int gs_notify_unregister_calling(P4(gs_notify_list_t *nlist,
  81.                     gs_notify_proc_t proc, void *proc_data,
  82.                     void (*unreg_proc)(P1(void *pdata))));
  83.  
  84. /*
  85.  * Notify the clients on a list.  If an error occurs, return the first
  86.  * error code, but notify all clients regardless.
  87.  */
  88. int gs_notify_all(P2(gs_notify_list_t *nlist, void *event_data));
  89.  
  90. /* Release a notification list. */
  91. void gs_notify_release(P1(gs_notify_list_t *nlist));
  92.  
  93. #endif /* gsnotify_INCLUDED */
  94.